home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / umich / falcon / programm.ing / nt_dsp1.lzh / NT_DSP1.MSA / FLOAT / FPDIV.ASM < prev    next >
Assembly Source File  |  1989-01-24  |  4KB  |  102 lines

  1. ;
  2. ; This program originally available on the Motorola DSP bulletin board.
  3. ; It is provided under a DISCLAIMER OF WARRANTY available from
  4. ; Motorola DSP Operation, 6501 Wm. Cannon Drive W., Austin, Tx., 78735.
  5. ; Last Update 5 Oct 87   Version 2.0
  6. ;
  7. fpdiv   ident   2,0
  8. ;
  9. ; MOTOROLA DSP56000/1 FPLIB VERSION 2
  10. ;
  11. ; FPDIV - FLOATING POINT DIVIDE SUBROUTINE
  12. ;
  13. ; Entry points: fdiv_xa R = A / X
  14. ;               fdiv_xy R = Y / X
  15. ;
  16. ;       m = 24 bit mantissa (two's complement, normalized fraction)
  17. ;
  18. ;       e = 14 bit exponent (unsigned integer, biased by +8191)
  19. ;
  20. ; Input variables:
  21. ;
  22. ;   X   x1 = ma  (normalized)
  23. ;       x0 = ea
  24. ;
  25. ;   Y   y1 = my  (normalized)
  26. ;       y0 = ey
  27. ;
  28. ;   A   a2 = sign extension of ma
  29. ;       a1 = ma  (normalized)
  30. ;       a0 = zero
  31. ;
  32. ;       b2 = sign extension of ea (always zero)
  33. ;       b1 = ea
  34. ;       b0 = zero
  35. ;
  36. ; Output variables:
  37. ;
  38. ;   R   a2 = sign extension of mr
  39. ;       a1 = mr  (normalized)
  40. ;       a0 = zero
  41. ;
  42. ;       b2 = sign extension of er (always zero)
  43. ;       b1 = er
  44. ;       b0 = zero
  45. ;
  46. ; Error conditions:     Set CCR L=1 if divide by zero error.  Result is
  47. ;                       set to the maximum floating point value having
  48. ;                       the same sign as the dividend if the dividend
  49. ;                       is non-zero.  Result is set to floating point
  50. ;                       zero if the dividend is zero.  The CCR L bit
  51. ;                       remains set until cleared by the user.
  52. ;
  53. ;                       Set CCR L=1 if floating point overflow.  Result
  54. ;                       is set to the maximum floating point value of the
  55. ;                       correct sign.  The CCR L bit remains set until
  56. ;                       cleared by the user.
  57. ;
  58. ;                       Set CCR L=1 if floating point underflow.  Result
  59. ;                       is set to floating point zero.  The CCR L bit
  60. ;                       remains set until cleared by the user.
  61. ;
  62. ; Assumes n0, m0, shift constant table and scaling modes
  63. ; initialized by previous call to the subroutine "fpinit".
  64. ;
  65. ; Alters Data ALU Registers
  66. ;       a2      a1      a0      a
  67. ;       b2      b1      b0      b
  68. ;       y1                      x0
  69. ;
  70. ; Alters Address Registers
  71. ;       r0
  72. ;
  73. ; Alters Program Control Registers
  74. ;       pc      sr               
  75. ;
  76. ; Uses 0 locations on System Stack
  77. ;
  78. ;
  79. fdiv_xy tfr     y0,b    y1,a            ;get ey, my
  80. fdiv_xa sub     x0,b    fp_space:fp_ebias,x0 ;calculate er' = ea - ex,get ebias
  81.         add     x0,b                    ;add ebias to er'
  82.         tfr     x1,b    b,r0            ;get mx, save er'
  83.         tst     b                       ;check for divisor mx = 0
  84.         jne     _div1                   ;jump if divisor not zero
  85.         tst     a                       ;check for dividend ma = 0
  86.         jne     limit                   ;jump if dividend not zero
  87.         or      #$40,ccr                ;set L=1 for divide by zero error
  88. _div1   asr     a       a,b             ;force fractional quotient, copy ma
  89.         jeq     done                    ;jump if dividend ma = 0 (underflow)
  90.         abs     a       (r0)+           ;make dividend positive, adjust er'
  91.         eor     x1,b                    ;calculate quotient sign
  92.         and     #$fe,ccr                ;clear carry (quotient sign bit)
  93.         rep     #24                     ;repeat for 24 bit quotient
  94.         div     x1,a                    ;generate one quotient bit
  95.         jpl     _qpos                   ;jump if positive quotient
  96.         neg     a                       ;negate mr' for negative quotient
  97. _qpos   move    a0,a                    ;get quotient mr'
  98.         tst     a                       ;normalize mr' 1 extra bit
  99.         norm    r0,a                    ;shift 1 bit and update exponent by 1
  100.         jmp     norm1                   ;normalize and check for errors
  101.